import cloud from '@lafjs/cloud'
let dbName = "order-discount-record"
const db = cloud.mongo.db
let data

export default async function (ctx: FunctionContext) {
  data = ctx.body.data
  switch (ctx.body.type) {
    case "add":
      return await cloud.utils.addData(dbName, data)
      break;
    case "query":
      return query()
      break;
    default:
      break;
  }
}

async function query() {
  let aa = await db.collection(dbName).find({ orderId: data._id }).toArray()
  return cloud.utils.requestReturn({ data: aa })
}
